#include <cstdio>
struct ulamek{
	int licznik;
	int mianownik;
};
int policz(int * tab, int tLen){
	int liczba = 0;
	int inkr = 1;

	for(int i = tLen-1; i >= 0;i--){
		int x = static_cast<int>(tab[i]);
		x = x - 48;
		liczba = (x*inkr) + liczba;
		inkr = inkr*10;
	}
	return liczba;

}

int main() {
		
	int k, ile, index;
	int wail;
	struct ulamek ul[100];
	int u[10];
	int c;

	scanf("%i", &k);
	for(int i = 0; i < k; i++)
	{
		int ile = getchar();
		unsigned char j = 0, wariant = 0;
		int liczba = 0, max;

		do{
			max = 0;
			c = getchar();
			while(((char)c)!=' '){
				u[j++]=c;
				c = getchar();
			}

 			max = policz(u,j);
			struct ulamek *u = new ulamek[max];
			int s = j = liczba = 0;
			c = getchar();
			while(c!=10) {

				while(((char)c)!='/' && ((char)c)!=' ' && c!=10){
					u[j++]=c;
					c = getchar();		
				}
				if(c=='/' || c==' ' || c==10){

					liczba = policz(u,j);
					j=0;
					if(wariant==0){
						ul->licznik = liczba;
						wariant = 1;
					}else{
						ul->mianownik = liczba;
						wariant = 0;
						u[s++]=*ul;
					}

				}
				if(c!=10) c = getchar();

			}

		}while((c = getchar())!=EOF);


	}

}

/*
		for(int i = 0; i < k; i++)
		{
			scanf("%i", &ile);		
			struct ulamek *u = new ulamek[ile];

				for(int j = 0; j < ile;j++)
				{

					int var = 1;
					if(getchar()==' '){
						if(var<3){
							c=getchar();
							while(c!=' ' && c!= EOF && c!='\\'){
								 tmp[m++]=(int)c;
								 if(m==max)
								 {
									 tmp2 = tmp;
									 tmp2 = new int[max*2];
									 tmp = new int[max*2];
								 }
							}
							int v = 1;
							 for(int s = m;s>0;s--)
							 {
								 if(v++>1) v = v*10;
								 liczMian = liczMian+tmp[s]*v;
							 }
							 if(var==1) u[j].l = liczMian;
							 if(var==2) u[j].m = liczMian;
							 var++;
						}
						delete [] tmp2;
						delete [] tmp;
					};


				}
				if(ile>1){
					struct ulamek ula;
					ula = sm(u,ile);
					u_wynik[index].l=ula.l;
					u_wynik[index].m=ula.m; 
					index++;
				} else if(ile==1) {
					u_wynik[index].m=(u[0]).m;
					u_wynik[index].l=(u[0]).l;
					index++;
				}
			delete [] u;
		}






		int main() {
		
	int k, ile, index;
	int wail;
	struct ulamek ul[100];
	int u[10];
	int c;

	scanf("%i", &k);
	for(int i = 0; i < k; i++)
	{
		int ile = getchar();
		unsigned char j = 0, wariant = 0;
		int liczba = 0, max;

		do{
			max = 0;
			c = getchar();
			while(((char)c)!=' '){
				u[j++]=c;
				c = getchar();
			}

 			max = policz(u,j);
			ulamek * tmp = new ulamek[max];
			max = max*2;

			int s = 0;
			int counter = 0;
			j = liczba = s;
			c = getchar();
			while(c!=10) {

				while(((char)c)!='/' && ((char)c)!=' ' && c!=10){
					u[j++]=c;
					c = getchar();		
				}
				if(c=='/' || c==' ' || c==10){

					liczba = policz(u,j);
					j=0;
					if(wariant==0){
						ul->licznik = liczba;
						wariant = 1;
					}else{
						ul->mianownik = liczba;
						wariant = 0;
						tmp[s++]=*ul;
					}

				}
				if(c!=10) c = getchar();

			}

		}while((c = getchar())!=EOF);


	}

}











		*/